package com.hbnu.system.controller;

import com.hbnu.system.core.base.Rest;
import com.hbnu.system.service.IdToStatsService;
import com.hbnu.system.service.StatsToIdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/IdAndStats")
@Api(tags = "id和文字转换")
public class IdAndStatsController {

    @Autowired
    private IdToStatsService idToStatsService;

    @Autowired
    private StatsToIdService statsToIdService;

    @ApiOperation("用户工号查找主键id")
    @PostMapping("/AccountToid")
    public Rest<String> AccountToid(String account){
        String accountToId = statsToIdService.AccountToId(account);
        return Rest.success(accountToId);
    }

    @ApiOperation("用户所有作者查找其主键id")
    @GetMapping("/AllahourToid")
    public Rest<String> AllahourToid(String allahouraccount){
        String allahourid = statsToIdService.AllauthorAccouhtToId(allahouraccount);
        return Rest.success(allahourid);
    }

    @ApiOperation("部门名称查找部门id")
    @GetMapping("/DeptToid")
    public Rest<String> DeptToid(String dept){
        String deptid = statsToIdService.DeptToId(dept);
        return Rest.success(deptid);
    }

    @ApiOperation("用户id查找用户名称")
    @PostMapping("/IdToaccount")
    public Rest<String> IdToaccount(String id){
        String name = idToStatsService.IdToName(id);
        return Rest.success(name);
    }

    @ApiOperation("用户所有作者id查找用户所有作者名称")
    @GetMapping("/IdToallahour")
    public Rest<String> IdToallahour(String allahouraccountid){
        String allahour = idToStatsService.IdToAllauthor(allahouraccountid);
                statsToIdService.AllauthorAccouhtToId(allahouraccountid);
        return Rest.success(allahour);
    }

    @ApiOperation("部门id查找部门名称")
    @GetMapping("/IdTodept")
    public Rest<String> IdTodept(String deptid){
        String dept = idToStatsService.IdToDept(deptid);
        return Rest.success(dept);
    }
}


